﻿-- =============================================
-- Author:		Kevin Orbaker
-- Create date: 10/08/2007
-- Description:	Select alert history counts by application..
-- =============================================
CREATE PROCEDURE [dbo].[usp_select_Faults_From_AlertHistoryReportByServiceFault] 
	-- Add the parameters for the stored procedure here
	@ApplicationName varchar(256),
	@ServiceName varchar(256) =null,
	@BeginDate datetime,
	@EndDate datetime
AS
BEGIN

	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

select 
  Fault.[FaultID]
  ,Fault.[NativeMessageID]
  ,Fault.[ActivityID]
  ,Fault.[Application]
  ,Fault.[Description]
  ,Fault.[ErrorType]
  ,Fault.[FailureCategory]
  ,Fault.[FaultCode]
  ,Fault.[FaultDescription]
  ,Fault.[FaultSeverity]
  ,Fault.[Scope]
  ,Fault.[ServiceInstanceID]
  ,Fault.[ServiceName]
  ,Fault.[FaultGenerator]
  ,Fault.[MachineName]
  ,Fault.[DateTime]
  ,Fault.[ExceptionMessage]
  ,Fault.[ExceptionType]
  ,Fault.[ExceptionSource]
  ,Fault.[ExceptionTargetSite]
  ,Fault.[ExceptionStackTrace]
  ,Fault.[InnerExceptionMessage]
 from 
	dbo.Fault
 Inner Join AlertHistory on AlertHistory.FaultId = Fault.FaultId
	WHERE AlertHistory.[Application] = @ApplicationName
	AND AlertHistory.[InsertedDate] between @BeginDate and @EndDate
    AND AlertHistory.ServiceName = @ServiceName 

END
